import Foundation

protocol DWJsonDataValue {}
extension NSData: DWJsonDataValue {}
extension Data: DWJsonDataValue {}

func dw_data(_ value: Any, type: Any.Type) -> DWJsonDataValue? {
    var data: Data?
    if let str = value as? String {
        data = str.data(using: .utf8)
    } else {
        data = value as? Data
    }
    guard let v = data else { return nil }
    return type is NSMutableData.Type ? NSMutableData(data: v) : v
}
